package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserCityServerCentreExtraAward;
import com.sc.nft.entity.dto.UserCityServerCentreExtraAwardPageListDTO;
import com.sc.nft.entity.vo.UserCityServerCentreExtraAwardPageListVO;
import com.sc.nft.mapper.UserCityServerCentreExtraAwardMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

@Slf4j
@Repository
public class UserCityServerCentreExtraAwardDao extends ServiceImpl<UserCityServerCentreExtraAwardMapper, UserCityServerCentreExtraAward> {

    public UserCityServerCentreExtraAward getByUserIdAndSumGtZero(Long userId) {
        return baseMapper.getByUserIdAndSumGtZero(userId);
    }


    public void saveSumSubtractOne(Long id){
        if (id==null) {
            return;
        }
        UpdateWrapper<UserCityServerCentreExtraAward>userCityServerCentreExtraAwardUpdateWrapper=new UpdateWrapper<>();
        userCityServerCentreExtraAwardUpdateWrapper.eq("id",id);
        userCityServerCentreExtraAwardUpdateWrapper.setSql("sum=sum-1");
        update(userCityServerCentreExtraAwardUpdateWrapper);
    }

    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }

    public Page<UserCityServerCentreExtraAwardPageListVO> getPageList(UserCityServerCentreExtraAwardPageListDTO userCityServerCentreExtraAwardPageListDTO) {
        return baseMapper.getPageList(userCityServerCentreExtraAwardPageListDTO.toMp(),userCityServerCentreExtraAwardPageListDTO);
    }
}
